#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>

using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Node {
   public:
    int val;
    Node* next;
    Node* random;

    Node(int _val) {
        val = _val;
        next = NULL;
        random = NULL;
    }
};

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
   public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        int p_val = p->val, q_val = q->val, r_val = root->val;
        if ((p_val - r_val) * (q_val - r_val) <= 0) return root;
        else if (p_val > r_val && q_val > r_val) return lowestCommonAncestor(root->right, p, q);
        else if (p_val < r_val && q_val < r_val) return lowestCommonAncestor(root->left, p, q);
        return root;
    }
};

int main() {
    cout << "Hello, World!";
    // Solution()
    return 0;
}
